<?php
/**
 * bll info
 * @package app-member_lib_bll_member
 */
load_lib('/bll/member/base');
load_lib('/dao/member/infodao');
/**
 * bll info
 * 
 * @author pandajingjing
 * @package app-member_lib_bll_member
 */
class bll_member_info extends bll_member_base{

	/**
	 * 获取用户基础信息
	 * 
	 * @param int $p_intUserID       	
	 * @return array/null
	 */
	function getUserBaseDetail($p_intUserID){
		return dao_member_infodao::getUserBaseDetail($p_intUserID);
	}

	/**
	 * 更新用户基础信息
	 * @param int $p_intUserID
	 * @param string $p_strNickName       	
	 * @param string $p_strEmail       	
	 * @param int $p_intGender  
	 * @param int $p_intTime     	
	 * @return true/array
	 */
	function updUserBaseDetail($p_intUserID,$p_strNickName,$p_strEmail,$p_intGender,$p_intTime){
		$bolErrFnd=false;
		$arrErrInfo=array();
		if(!isset($p_intUserID[0])){
			$bolErrFnd=true;
			$arrErrInfo[]='Sys_Error_NoUserID';
		}
		load_lib('/util/member');
		if(isset($p_strNickName[0])){
			$mixResult=util_member::chkNickName($p_strNickName);
			if(true!==$mixResult){
				$bolErrFnd=true;
				$arrErrInfo[]=$mixResult;
			}
		}
		if(isset($p_strEmail[0])){
			$mixResult=util_member::chkEmail($p_strEmail);
			if(true!==$mixResult){
				$bolErrFnd=true;
				$arrErrInfo[]=$mixResult;
			}
		}
		if(isset($p_intGender[0])){
			if(in_array($p_intGender,array( 
					1,
					2 
			))){

			}else{
				$bolErrFnd=true;
				$arrErrInfo[]='Err_Logic_Gender_Deregulation';
			}
		}
		if($bolErrFnd){
			return $arrErrInfo;
		}
		if($this->chkUserInfoExist($p_strNickName,'NICKNAME',$p_intUserID)){
			$bolErrFnd=true;
			$arrErrInfo[]='Err_Logic_NickName_Exist';
		}
		if($bolErrFnd){
			return $arrErrInfo;
		}
		if($this->chkUserInfoExist($p_strEmail,'EMAIL',$p_intUserID)){
			$bolErrFnd=true;
			$arrErrInfo[]='Err_Logic_Email_Exist';
		}
		if($bolErrFnd){
			return $arrErrInfo;
		}
		$arrParam=array( 
				'USERID'=>$p_intUserID,
				'NICKNAME'=>$p_strNickName,
				'EMAIL'=>$p_strEmail,
				'GENDER'=>$p_intGender 
		);
		dao_member_infodao::updUserBase($arrParam);
		$arrModInfoMsg=array( 
				'MSGTYPE'=>4,
				'USERID'=>$p_intUserID,
				'EMAIL'=>$p_strEmail,
				'LASTUPD'=>$p_intTime 
		);
		dao_member_infodao::addUserQueue($arrModInfoMsg);
		return true;
	}

	/**
	 * 更新用户密码
	 * @param int $p_intUserID
	 * @param string $p_strOldPwd
	 * @param string $p_strNewPwd
	 * @param string $p_strNewPwdCfm
	 * @return true/array
	 */
	function updUserPwd($p_intUserID,$p_strOldPwd,$p_strNewPwd,$p_strNewPwdCfm){
		$bolErrFnd=false;
		$arrErrInfo=array();
		load_lib('/util/member');
		if(!isset($p_intUserID[0])){
			$bolErrFnd=true;
			$arrErrInfo[]='Sys_Error_NoUserID';
		}
		if(!isset($p_strOldPwd[0])){
			$bolErrFnd=true;
			$arrErrInfo[]='Err_Logic_UserOldPwd_NoValue';
		}
		if(isset($p_strNewPwd[0]) and isset($p_strNewPwdCfm[0])){
			if($p_strNewPwd!==$p_strNewPwdCfm){
				$bolErrFnd=true;
				$arrErrInfo[]='Err_Logic_UserNewPwd_NotConfirm';
			}
		}else{
			$bolErrFnd=true;
			$arrErrInfo[]='Err_Logic_UserNewPwd_NoValue';
		}
		if($bolErrFnd){
			return $arrErrInfo;
		}
		if($p_strOldPwd==$p_strNewPwd){
			$bolErrFnd=true;
			$arrErrInfo[]='Err_Logic_UserNewPwdOldPwd_Same';
		}
		if($bolErrFnd){
			return $arrErrInfo;
		}
		$arrUserBaseDetail=$this->getUserBaseDetail($p_intUserID);
		$strCryptOldPwd=$this->generateCryptPwd($p_strOldPwd,$arrUserBaseDetail['USERNAME']);
		if($strCryptOldPwd!=$arrUserBaseDetail['USERPWD']){
			$bolErrFnd=true;
			$arrErrInfo[]='Err_Logic_UserOldPwd_NotMatch';
		}
		if($bolErrFnd){
			return $arrErrInfo;
		}
		$strCryptNewPwd=$this->generateCryptPwd($p_strNewPwd,$arrUserBaseDetail['USERNAME']);
		$arrParam=array( 
				'USERID'=>$p_intUserID,
				'USERPWD'=>$strCryptNewPwd 
		);
		dao_member_infodao::updUserBase($arrParam);
		$arrModPwdMsg=array( 
				'MSGTYPE'=>3,
				'USERID'=>$p_intUserID,
				'USERNAME'=>$arrUserBaseDetail['USERNAME'],
				'USERPWD'=>$strCryptNewPwd 
		);
		dao_member_infodao::addUserQueue($arrModPwdMsg);
		return true;
	}

}